/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests;

import java.util.ArrayList;


/**
 * This class contains the description of the class tests results.
 */
public class TestClass
{
    /** Name of the class. */
    private String className;

    /** List of errors. */
    private ArrayList errorsList;

    /** List of failures. */
    private ArrayList failsList;

    /** List of success. */
    private ArrayList successList;

    /** Number of tests. */
    private int methodTestsNb;

    /** Current Method. */
    private TestMethod currentMethod;

    /**
     * Constructor of the class.
     */
    public TestClass()
    {
        errorsList = new ArrayList();
        failsList = new ArrayList();
        successList = new ArrayList();

        methodTestsNb = 0;
    }

    /**
     * Constructor with class name.
     *
     * @param name The name to set.
     */
    public TestClass(String name)
    {
        this();
        setClassName(name);
    }

    /**
     * Defines the name of the class.
     *
     * @param name  The name to set.
     */
    public void setClassName(String name)
    {
        className = name;
    }

    /**
     * Indicates the beginning of a method test.
     *
     * @param method The name of the method.
     */
    public void beginTestMethod(String method)
    {
        currentMethod = new TestMethod(method);
    }

    /**
     * Indicates the end of a method test.
     */
    public void endTestMethod()
    {
        if (currentMethod.hasMethodErrors())
        {
            errorsList.add(currentMethod);
        }
        else if (currentMethod.hasMethodFailures())
        {
            failsList.add(currentMethod);
        }
        else
        {
            successList.add(currentMethod);
        }

        methodTestsNb++;
    }

    /**
     * Adds an error.
     *
     * @param error  The error message.
     */
    public void addErrors(String error)
    {
        currentMethod.addErrors(error);
    }

    /**
     * Adds a failure.
     *
     * @param fail The failure message.
     */
    public void addFails(String fail)
    {
        currentMethod.addFails(fail);
    }

    /**
     * Adds a success.
     *
     * @param success  The success message.
     */
    public void addSuccess(String success)
    {
        currentMethod.addSuccess(success);
    }

    /**
     * Gets the errors list.
     *
     * @return The list of errors.
     */
    public ArrayList getMethodsError()
    {
        return errorsList;
    }

    /**
     * Gets the failures list.
     *
     * @return The list of failures.
     */
    public ArrayList getMethodsFailure()
    {
        return failsList;
    }

    /**
     * Gets the success list.
     *
     * @return The list of success.
     */
    public ArrayList getMethodsSuccess()
    {
        return successList;
    }

    /**
     * Gets the number of method tests for the class.
     *
     * @return The tests number.
     */
    public int getMethodTestsNumber()
    {
        return methodTestsNb;
    }

    /**
     * Gets the number of tests in error for the class.
     *
     * @return The tests number.
     */
    public int getErrorTestsNumber()
    {
        return errorsList.size();
    }

    /**
     * Gets the number of tests in failure for the class.
     *
     * @return The tests number.
     */
    public int getFailureTestsNumber()
    {
        return failsList.size();
    }

    /**
     * Gets the number of successfull tests for the class.
     *
     * @return The tests number.
     */
    public int getSuccessTestsNumber()
    {
        return successList.size();
    }

    /**
     * Gets the name of the class.
     *
     * @return The name.
     */
    public String getClassName()
    {
        return className;
    }

    /**
     * Indicates if the class tests contain errors.
     *
     * @return true if the class tests contain error, false otherwise.
     */
    public boolean hasClassErrors()
    {
        return !errorsList.isEmpty();
    }

    /**
     * Indicates if the class tests contain failures.
     *
     * @return true if the class tests contain failure, false otherwise.
     */
    public boolean hasClassFailures()
    {
        return !failsList.isEmpty();
    }

    /**
     * Indicates if the class tests contain success.
     *
     * @return true if the class tests contain success, false otherwise.
     */
    public boolean hasClassSuccess()
    {
        return !successList.isEmpty();
    }
}
